/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: 沈小白 2020-07-22 $
 */<template> 
	<view class="container" v-if="recommend">
		<navigator class="copyright" url="#" role="navigation" v-if="ad">
			<image class="wh100" :src="hostUrl+ad.ad_code" role="img"></image>
		</navigator>
		<view>
			<swiper class="swiper_box" :duration="1000" :interval="3000" :current="1">
				<block v-for="(item,index1) in recommend" :key="index1">
					<block v-if="index1%3==0">
						<swiper-item style="position: absolute; width: 100%; height: 100%; transform: translate(0%, 0px) translateZ(0px);">
							<block v-for="(item,index) in recommend" :key="index">
								<block v-if="index>=index1 && index <=index1 + 2">
									<navigator class="slide-item" :url="'/pages/goods/goodsInfo/goodsInfo?goods_id='+item.goods_id" role="navigation">
										<view class="image-wrap">
											<image class="wh100" :src="hostUrl+'/mall/goods/thumb_image?goods_id='+ item.goods_id+'&width='+goodsImgWidth+'&height='+goodsImgHeight+'&'+item.goods_id+'.'+imgType"role="img"></image>
										</view>
										<view class="current-price">￥{{item.shop_price.toFixed(2)}}</view>
										<view class="market-price">￥{{item.market_price.toFixed(2)}}</view>
									</navigator>
								</block>
							</block>
					
						</swiper-item>
					</block>
				</block>

			</swiper>
		</view>
		<view class="recommend">
			<view class="re-title">推荐大牌</view>
			<view class="tab-list">
				<block v-for="(item,index) in brandData" :key="index">
				<navigator class="brand-item" :url="'/pages/goods/search/search?brand_id='+item.id" role="navigation">
					<image :src="hostUrl+item.logo" role="img"></image>
				</navigator>
				</block>
			</view>
		</view>
	</view>
</template>

<script>
	import {getClassifyAd,getBrand,getBrandRecommend} from "@/api/api.js";
	import config from "@/api/config.js";
	import {mapState} from 'vuex';
	export default {
		data() {
			return {
				hostUrl:config.host,//图片路径前缀
				ad:"",//广告
				p:1,//默认初始显示10条
				brandData:[],//数据
				recommend:"",//推荐商品
				total:"",//条数
			};
		},
		onLoad(){
			this._getClassifyAd(533);
			
			
		},
		computed: {
			...mapState(['imgType','goodsImgHeight','goodsImgWidth'])
		},
		methods:{
			_getClassifyAd(pid){ //品牌街广告图 固定图片id 533
				getClassifyAd(pid).then(res=>{
					console.log(res)
					this.ad=res.records[0];
				}).then(()=>{
					this._getBrand(this.p);
				}).then(()=>{
					this._getBrandRecommend()
				})
			},
			_getBrand(p){//品牌方
				getBrand(p).then(res=>{
					console.log(res);
					this.brandData=this.brandData.concat(res.records);
					this.total=res.total;
				})
			},
			_getBrandRecommend(){
				getBrandRecommend().then(res=>{
					this.recommend=res.records
					console.log(res)
				})
			},
			onReachBottom(){//下拉加载数据
				
				if(this.brandData.length===this.total){
					common.toast("none","加载完了",2000)
					 return false;
				}
				this.p++;
				this._getBrand(this.p);
				
				
			},
		}
	}
</script>

<style lang="scss">
	.copyright {
		width: 100%;
		height: 296rpx;
	}

	.wh100 {
		width: 100%;
		height: 100%;
	}

	.swiper_box {
		background-color: $index-bg-color;
		padding: 20rpx 0;
		height: 180px;
	}

	.slide-item {
		float: left;
		width: 33.33%;
		text-align: center;
		font-size: 24rpx;
	}

	.current-price {
		color: $text-color-master;
		margin: 10rpx 0;
	}

	.market-price {
		color: $text-color-hint;
		text-decoration: line-through;
	}

	.image-wrap {
		width: 228rpx;
		height: 228rpx;
		margin: 0 auto;
	}

	.recommend {
		background-color: $index-bg-color;
		margin-top: 20rpx;
	}

	.re-title {
		line-height: 64rpx;
		font-size: 32rpx;
		padding-left: 20rpx;
		color: $text-color;
	}

	.tab-list {
		border-top: 1px solid $cut-bg-color;
	}

	.brand-item {
		float: left;
		width: 25%;
		height: 120rpx;
		padding-top: 7rpx;
		box-sizing: border-box;
		border-bottom: 1px solid $cut-bg-color;
		border-right: 1px solid $cut-bg-color;
		text-align: center;
	}

	.brand-item image {
		width: 150rpx;
		height: 106rpx;
	}
</style>
